<?php
//registry nav menu
add_theme_support('menus');
register_nav_menu('nav' , 'nav-menu');
//register Main Sidebar 
if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'name'          => 'Main Sidebar',
        'before_widget' =>  '<div class="box border-top">',
        'after_widget'  =>  '</div>',
        'before_title'  =>  '<h2>',
        'after_title'   =>  '</h2>',
    ));
}
//register Ads widget
if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'name'          => 'Ads Sidebar',
        'before_widget' =>  '<div class="box border-top">',
        'after_widget'  =>  '</div>',
        'before_title'  =>  '<h2>',
        'after_title'   =>  '</h2>',
    ));
}
//register Twitter sidebar
if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'name'          => 'Twitter Widget',
        'before_widget' =>  '<div class="status">',
        'after_widget'  =>  '</div>',
		'before_title'  =>  '<span class="twt">',
        'after_title'   =>  '</span>',
    ));
}
//register Recent Comment widget
if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'name'          => 'Recent Comment',
        'before_widget' =>  '<div class="recent">',
        'after_widget'  =>  '</div>',
        'before_title'  =>  '<h2 class="title">',
        'after_title'   =>  '</h2>',
    ));
}
//Pupular func
function popularPosts($num) {
    global $wpdb;
 
    $posts = $wpdb->get_results("SELECT comment_count, ID, post_title,post_date FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , $num");
 
    foreach ($posts as $post) {
        setup_postdata($post);
        $id = $post->ID;
        $title = $post->post_title;
        $date = $post->post_date;
        $count = $post->comment_count;
 
        if ($count != 0) {
            $popular .= '<li>';
            $popular .= '<a href="' . get_permalink($id) . '" title="' . $title . '"><span class="post-date">'.$date.'</span><span class="post-name">- '. $title . '</span></a> ';
            $popular .= '</li>';
        }
    }
    return $popular;
}
//Wordpress CoreNav
function wp_corenavi() {
 global$wp_query, $wp_rewrite;
 $pages= '';
 $max= $wp_query->max_num_pages;
 if(!$current= get_query_var('paged')) $current= 1;
 $a['base'] = ($wp_rewrite->using_permalinks()) ? user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged') : @add_query_arg('paged','%#%');
 if( !empty($wp_query->query_vars['s']) ) $a['add_args'] = array( 's'=> get_query_var( 's') );
 $a['total'] = $max;
 $a['current'] = $current;
$total= 1; //1 - hiển thị "Page N of N", 0 - không hiển thị
 $a['mid_size'] = 5; //số phân trang hiện bên trái và phài của trang hiện tại
 $a['end_size'] = 1; //số phân trang bắt đầu và kết thúc
 $a['prev_text'] = '&laquo; Previous'; //chữ "Previous page"
 $a['next_text'] = 'Next &raquo;'; //chữ "Next page"
 if($max> 1) echo'<div class="pagenavi">';
 if($total== 1 && $max> 1) $pages= '<span>Page '. $current. ' of '. $max. '</span>'."\n";
 echo$pages. paginate_links($a);
 if ($max > 1) echo '</div>';}

//Comment Funct
function zyn_comment($comment, $args, $depth)    {
    $GLOBALS['comment'] = $comment; ?>
    <li <?php comment_class();?> id="li-comment-<?php comment_ID();?>">
    
        <div id="comment-<?php comment_ID();?>" class="clearfix">
            <div class="comment-author vcard">
                
                <?php printf(__('<p class="fn">%s</p>'), get_comment_author_link()); ?>
                <?php if($comment->comment_approved == '0') : ?>
                <em><?php echo 'Your coment is waiting for moderation.';?></em>
                <?php endif; ?>
                <p class="comment-meta commentmetadata">
                <?php printf(get_comment_date());?><?php edit_comment_link(__('(Edit)'),' ',''); ?>
                </p><!--end .comment-meta-->
            </div><!-- end comment autho vcard-->
        
         <div class="commentBody">
            
            <?php comment_text(); ?>
            <p class="reply">
            <?php comment_reply_link(array_merge($args,array('depth' => $depth, 'max_depth'=> $args['max_depth'])));?>
            </p><!--end .reply-->
        </div><!--end #commentBody--> 
        </div><!--end #comment-author-vcard-->
<?php }?>